package reader;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.bind.DatatypeConverter;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.shhic.itsed.mws.deviceintf.AntennaProtocol;
import com.shhic.itsed.mws.deviceintf.RawTagBank;
import com.shhic.itsed.mws.deviceintf.RawTagField;
import com.shhic.itsed.mws.deviceintf.ReaderCommand;
import com.shhic.itsed.mws.deviceintf.ReaderCommandType;
import com.shhic.itsed.mws.deviceintf.ReaderLinkStatusEnum;
import com.tjkcht.midware.reader.Rd30Manager;

import rdp_msg.Rdp.rdp_request;
import rdp_msg.Rdp.rdp_request.HeadType;

public class ReaderManagerTest1 {
	private String ip = "192.168.11.182";
	private int port = 5084;
	private Rd30Manager rm;
	public ResultCallBack call=new ResultCallBack();

	@Before
	public void setUp() throws Exception {
		rm = new Rd30Manager();
	}

	@After
	public void tearDown() throws Exception {
		rm.close();
	}

	@Test
	public void test() {
		rm.initReader(ip, port);
		try {
			assertEquals(ReaderLinkStatusEnum.CONNECTING, rm.queryDeviceLinkstatus(ip));
			///send reader config
			ReaderCommand cmd = new ReaderCommand();
			cmd.setReaderIp(ip);
			cmd.setReaderPort(port);
			cmd.setReaderCommandType(ReaderCommandType.CYCLE);
			Set<AntennaProtocol> antennaProtocolSet=new HashSet<AntennaProtocol>();
			AntennaProtocol ap=new AntennaProtocol();
			ap.setAntennaNo(2);
			antennaProtocolSet.add(ap);
			Set<String> plSet=new HashSet<String>();
			plSet.add("EPC");
			ap.setProtocols(plSet);			
			cmd.setAntennaProtocolSet(antennaProtocolSet);
			List<RawTagField> readTagFieldList=new ArrayList<RawTagField>();
			RawTagField field=new RawTagField();
			field.setBank(RawTagBank.EPCBANK);
			field.setOffset(0);
			field.setLength(2);			
			readTagFieldList.add(field);
			cmd.setReadTagFieldList(readTagFieldList);
			rm.dispatchReadCommand(ip, cmd, 0, call);					
			Thread.sleep(1000000);			
			rm.stopReaderCommand(ip);
			//Thread.sleep(20000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
